package org.backend.enums;

import lombok.Getter;

@Getter
public enum ProductStatus {

    AVAILABLE(0, "在售"),
    SOLD(1, "已售出"),
    INACTIVE(2, "下架"),
    RESERVE(3, "待发货"),
    SHIPPED(4, "已发货");

    private final Integer status;
    private final String desc;

    ProductStatus(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    // 根据 status 获取对应的枚举对象
    public static ProductStatus fromStatus(Integer status) {
        for (ProductStatus productStatus : ProductStatus.values()) {
            if (productStatus.getStatus().equals(status)) {
                return productStatus;
            }
        }
        throw new IllegalArgumentException("Unexpected value: " + status);
    }

    // 根据描述获取对应的 status（字符串转数字）
    public static Integer fromDesc(String desc) {
        for (ProductStatus productStatus : ProductStatus.values()) {
            if (productStatus.getDesc().equals(desc)) {
                return productStatus.getStatus();
            }
        }
        throw new IllegalArgumentException("Unexpected description: " + desc);
    }
}
